package com.yunxin.core.infra.persistence.repository.order;

import com.yunxin.core.domain.model.order.OrderUserApplyDetail;
import com.yunxin.core.domain.model.order.OrderUserApplyDetailRepository;
import com.yunxin.core.infra.persistence.converter.OrderConverter;
import com.yunxin.core.infra.persistence.entity.order.OrderUserApplyDetailDO;
import com.yunxin.core.infra.persistence.mapper.order.OrderUserApplyDetailExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class OrderUserApplyDetailRepositoryImpl implements OrderUserApplyDetailRepository {

    private final OrderUserApplyDetailExtendMapper orderUserApplyDetailExtendMapper;

    private final OrderConverter orderConverter;

    @Override
    public boolean saveOrderUserApplyDetail(OrderUserApplyDetail orderUserApplyDetail) {
        OrderUserApplyDetailDO orderUserApplyDetailDO =  orderConverter.formOrderUserApplyDetail(orderUserApplyDetail);
        int count = orderUserApplyDetailExtendMapper.insertSelective(orderUserApplyDetailDO);
        return count > 0;
    }

    @Override
    public boolean updateOrderUserApplyDetail(OrderUserApplyDetail orderUserApplyDetail) {
        OrderUserApplyDetailDO orderUserApplyDetailDO =  orderConverter.formOrderUserApplyDetail(orderUserApplyDetail);
        int count = orderUserApplyDetailExtendMapper.updateByPrimaryKeySelective(orderUserApplyDetailDO);
        return count > 0;
    }

    @Override
    public OrderUserApplyDetail getOrderUserApplyDetailByApplyOrderNo(String applyOrderNo) {
        OrderUserApplyDetailDO orderUserApplyDetailDO = orderUserApplyDetailExtendMapper.selectOrderUserApplyDetailByApplyOrderNo(applyOrderNo);
        return orderConverter.toOrderUserApplyDetail(orderUserApplyDetailDO);
    }
}
